package com.orzxlee.InterviewQuestions.Java_SE_Advanced.Demo_Observer;

import java.util.Enumeration;
import java.util.Vector;

public abstract class AbstractSubject implements  Subject {

    private Vector<Observer> vector = new Vector<Observer>();

    @Override
    public void add(Observer observer) {
        vector.add(observer);
    }

    @Override
    public void del(Observer observer) {
        vector.remove(observer);
    }

    /*通知Observer1 Observer2 */
    @Override
    public void notifyObservers() {
        //创建集合 保存 Observer对象
        Enumeration<Observer> enumo = vector.elements();
        //拿到其中一个Observer对象
        while (enumo.hasMoreElements()) {
            //调用Observer对象的更新方法
            enumo.nextElement().update();
        }
    }
}


